package com.admin.action;

import com.admin.service.AccountAdminService;
import com.data.bean.Account;
import com.data.util.CheckDataUtils;
import com.data.util.ImageLookUtils;
import com.user.action.IndexUserAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 管理员管理账号信息
 *
 * @author:HingLo
 * @create 2017-09-28 18:03
 **/
@Controller
@RequestMapping("/accountAdmin/admin/")
public class AccountAdminAction {
    @Autowired
    private AccountAdminService accountAdminService;
    @Autowired
    private IndexUserAction indexUserAction;

    /**
     * 查看账号的信息
     *
     * @param id      账号的唯id
     * @param request 请求request，自动注入
     * @return 返回字符串，自动解析到模板
     */
    @GetMapping("accountInfo")
    public String lookAccountInfoAction(String id, HttpServletRequest request) {
        Account account = null;
        if (CheckDataUtils.stringUtilsID(id)) {
            account = accountAdminService.lookAccountInfoService(id);
        }
        request.setAttribute("Account", account);
        return "/WEB-INF/admin/software/accountInfo";
    }

    /**
     * 开发账号的注册信息
     *
     * @param id 账号的id
     * @return 返回一个json格式的数据
     */
    @GetMapping("lookDeveloperInfo")
    @ResponseBody
    public List<?> lookDeveloperInfoAction(String id, int type) {
        return indexUserAction.getIndexUserService().lookDeveloperMassageService(id, type);
    }

    /**
     * 查看开发者的注册的认证向信息图片
     *
     * @param id
     * @param response
     */
    @GetMapping("lookDeveloperIcon")
    public void lookDeveloperIconAction(String id, HttpServletResponse response) {
        byte[] inputStream = indexUserAction.getIndexUserService().developerIconService(id);
        ImageLookUtils.responseImage(inputStream, response);

    }


}
